* This file provides codes the 2008, 2012, and 2016 ANES datasets, which must be
*	combined as the ANES Cumulative File does not contain the item asking
*	respondents their sexual orientation

do "/Users/jrthornton/Desktop/Replication/2008 code.do"
do "/Users/jrthornton/Desktop/Replication/2012 code.do"
do "/Users/jrthornton/Desktop/Replication/2016 code.do"

save "/Users/jrthornton/Desktop/Replication/2016_combined.dta" , replace
cd "/Users/jrthornton/Desktop/Replication/"
append using "2008_combined.dta"
append using "2012_combined.dta"

cd "/Users/jrthornton/Desktop/Replication/"
erase "2008_combined.dta"
erase "2012_combined.dta"
erase "2016_combined.dta"



svyset [pw=w]



set more off
replace income = . if income<1
replace interest = interest_old if year==2008


irt grm interviewer_assesment  interest  involvement 
predict soph_irt , latent
replace soph_irt = . if interviewer_assesment==.
replace soph_irt = . if interest == .
replace soph_irt = . if involvement == .
su soph_irt, meanonly
replace soph_irt = (soph_irt- r(min))/(r(max) - r(min))

irt hybrid (grm interest  involvement) (2pl house) 
predict soph_alt , latent
replace soph_alt = . if house==.
replace soph_alt = . if interest == .
replace soph_alt = . if involvement == .
su soph_alt, meanonly
replace soph_alt = (soph_alt- r(min))/(r(max) - r(min))


irt grm equality1 equality4 equality5 equality6 
predict equality_irt, latent 
su equality_irt, meanonly
replace equality_irt = (equality_irt- r(min)) /(r(max) - r(min))


irt hybrid (grm gay_discrimination gay_marriage) (2pl gay_adopt) 
predict gay_irt, latent 
replace gay_irt = . if gay_discrimination==.
replace gay_irt = . if gay_marriage==.
replace gay_irt = . if gay_adopt==.
su gay_irt , meanonly
replace gay_irt = (gay_irt- r(min)) /(r(max) - r(min))

* sem can't include factor variables — split up i.race: TABLE E4
gen white=0 if race!=1
replace white=1 if race==1
replace white=. if race==.
gen black=0 if race!=2
replace black=1 if race==2
replace black=. if race==.
gen latinx=0 if race!=3
replace latinx=1 if race==3
replace latinx=. if race==.
gen other=0 if race!=4
replace other=1 if race==4
replace other=. if race==.


save "/Users/jrthornton/Desktop/Replication/gay_rights.dta" , replace


